using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Chess;

namespace PDAChess
{
    public partial class frmMain: Form
    {
        private string pathMusic = "";
        private string _path = "";
        private Thread _thread = null;

        private ucGameOption ucGameOption = null;

        public frmMain()
        {            
            InitializeComponent();

            _path = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
            _path = _path.Replace(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].Name, "");
            ucGameOption = new ucGameOption();
            ucGameOption.CreateClick += new ucGameOption.Create_Click(ucGameOption_CreateClick);
            ucGameOption.CancelClick += new ucGameOption.Cancel_Click(ucGameOption_CancelClick);
            pnlGameCommand.Controls.Add(ucGameOption);
            pathMusic = _path + "sound\\"  + "hayhay.wav";

            ucGameOption.Hide();
        }
    
        void uc_OnCancelClick()
        {
            frmMatch frm = new frmMatch();
            frm.ShowDialog();
        }

        private void ucNewGame1_NewGameClick(object sender, EventArgs e)
        {            
            ucNewGame1.Hide();
            ucGameOption.Show();
        }

        void ucGameOption_CancelClick()
        {
            ucGameOption.Hide();
            ucNewGame1.Show();
        }

        void ucGameOption_CreateClick()
        {
            Program.Options = ucGameOption.Options;

            frmMatch frm = new frmMatch();
            frm.ShowDialog();
        }

        private void ucNewGame1_QuitClick(object sender, EventArgs e)
        {
            if (_thread != null)
            {
                _thread.Abort();
            }

            this.Close();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            PlayMusic();
        }

        private void PlayMusic()
        {
            if (_thread != null)
            {
                _thread.Abort();
            }
            _thread = new Thread(new ThreadStart(Play_Music));
            _thread.Priority = ThreadPriority.Highest;
            _thread.Start();
        }

        private void Play_Music()
        {
            XL_Nhac.PlayMusicLoop(pathMusic);
        }
    }
}